package com.pronhub.luowowo.website;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import com.pronhub.luowowo.website.web.Resolver.UserInfoArgumentResolver;
import com.pronhub.luowowo.website.web.interceptor.CheckedLoginInterceptor;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;


@SpringBootApplication
@EnableDubbo
public class WebSite implements WebMvcConfigurer {
    @Bean
    public CheckedLoginInterceptor checkedLoginInterceptor(){
        return new CheckedLoginInterceptor();
    }
    @Bean
    public UserInfoArgumentResolver userInfoArgumentResolver(){
        return new UserInfoArgumentResolver();
    }

    //对哪些资源进行过滤
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkedLoginInterceptor())
                //什么需要检查
                .addPathPatterns("/**")
                .excludePathPatterns("/userLogin")
                .excludePathPatterns("/userRegist")
                .excludePathPatterns("/sendverfyCode")
                .excludePathPatterns("/login.html")
                .excludePathPatterns("/regist.html")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/images/**");
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(userInfoArgumentResolver());
    }
    public static void main(String[] args) {
        SpringApplication.run(WebSite.class, args);
    }

}
